<!-- src/views/admin/AdminEditGame.vue -->
<template>
  <div class="container mx-auto px-4 py-8">
    <h1 class="text-2xl font-bold mb-4">编辑游戏</h1>
    <div v-if="loading" class="text-center py-8">
      <i class="fa fa-spinner fa-spin text-blue-500 text-2xl"></i>
    </div>
    <form v-else @submit.prevent="updateGame">
      <!-- 游戏表单字段 -->
      <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
        <div class="md:col-span-2">
          <label for="title" class="block text-sm font-medium text-gray-700 mb-1">游戏名称</label>
          <input v-model="game.title" type="text" id="title" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
        </div>
        <div>
          <label for="category" class="block text-sm font-medium text-gray-700 mb-1">游戏类别</label>
          <select v-model="game.category" id="category" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
            <option value="角色扮演">角色扮演</option>
            <option value="动作冒险">动作冒险</option>
            <option value="射击">射击</option>
            <option value="策略">策略</option>
            <option value="模拟">模拟</option>
          </select>
        </div>
      </div>

      <!-- 其他字段 -->

      <div class="flex justify-end">
        <button type="submit" class="mt-4 bg-blue-500 hover:bg-blue-600 text-white font-medium py-2 px-4 rounded">保存修改</button>
      </div>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      game: {
        id: null,
        title: '',
        description: '',
        category: '',
        releaseDate: '',
        coverImage: ''
      },
      loading: true
    };
  },
  async created() {
    // 获取游戏数据
    try {
      const gameId = this.$route.params.id;
      // const response = await this.$axios.get(`/api/games/${gameId}`);
      // this.game = response.data;
      this.loading = false;
    } catch (error) {
      console.error('获取游戏数据失败', error);
      this.loading = false;
    }
  },
  methods: {
    async updateGame() {
      try {
        // const response = await this.$axios.put(`/api/games/${this.game.id}`, this.game);
        console.log('游戏更新成功');
        this.$router.push({ name: 'AdminGames' });
      } catch (error) {
        console.error('更新失败', error);
      }
    }
  }
}
</script>